// require('babel-register');
// require('babel-polyfill');

const Koa = require('koa');
const Cors = require('kcors');
const Logger = require('koa-logger');

const Bodyparser = require('koa-bodyparser');
import { SERVER_PORT } from './constants/constant.js';
//const path = require('path');
//const serve = require('koa-static');

import route from './route.js';

const app = new Koa();

//app.use(Cors({credentials: true}));
app.use(Logger());
app.use(Bodyparser({
    onerror: (err, ctx) => {
      ctx.throw('Error parsing the body information', 422);
    }
}));
app.use(route.routes());

app.listen(SERVER_PORT);
console.log("server start at http://localhost:"+SERVER_PORT);